package app

import app.controller.UserController
import app.util.Log
import spark.Spark.*
import spark.servlet.SparkApplication

// IDEA 调试启动
fun main(args: Array<String>) {
    exception(Exception::class.java) { e, _, _ -> e.printStackTrace() }

    path("/api") {
        before("/*") { q, _ ->
            Log.ua(q)
        }

        path("/users") {
            get("", UserController.list)
            get("/:id", UserController.info)
            post("/create", UserController.create)
            post("/update/:id", UserController.update)
            post("/delete/:id", UserController.delete)
        }
    }
}

// TOMCAT 启动
class Application: SparkApplication {
    override fun init() {
        exception(Exception::class.java) { e, _, _ -> e.printStackTrace() }

        path("/api") {
            before("/*") { q, _ ->
                Log.ua(q)
            }

            path("/users") {
                get("", UserController.list)
                get("/:id", UserController.info)
                post("/create", UserController.create)
                post("/update/:id", UserController.update)
                post("/delete/:id", UserController.delete)
            }
        }
    }
}